#include<bits/stdc++.h>
using namespace std;
int n,m,k;
int ya[100005],c[100005],a[100005],d[100005],tree[100005];
int main()
{
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>ya[i];
    for(int i=1;i<=m;i++)cin>>c[i];
    //"DIF"for "k" here
    while(pow(2,k)<n)k++;
    //check k is right?

    //"cin" here
    for(int i=1;i<=k;i++)
    {
        for(int j=1;j<=pow(2,(k-i));i++)
        {
            char c;
            cin>>c;
            int w=pow(2,(k-i+1))+2*(j-1);
            if(c==0)d[w]=1;
            else d[w+1]=1;
        }
    }

    for(int i=1;i<=pow(2,(k+1)-1);i++)cout<<d[i]<<' ';
    cout<<'\n';

    int T;
    cin>>T;

    while(T--)
    {
        memset(a,-1,sizeof(a));
        int x[5];
        for(int i=0;i<4;i++)cin>>x[i];
        for(int i=1;i<=n;i++)
            a[i]=ya[i]^x[i%4];
        for(int i=1;i<=m;i++)
        {
            //add"DIF"here
            int pw1=pow(2,k),pw2=pow(2,(k+1));
            for(int i=pw1;i<=pw2-1;i++)
                tree[i]=a[i-pw1+1];


            for(int i=1;i<=pow(2,(k+1)-1);i++)cout<<tree[i]<<' ';
            cout<<'\n';
        }
    }
}
/*
I think I will give up.
I can do this at home instead of in competition.
I can get 100+20=120pts now.
Its not a good point.
Now I can get 100+20+(40)==(160)
160 is helplss.
125? maybe
18mins leter is time to AFO.
Goodbye for my oi life.
I love my oi life,it brought me happiness and made me confident.
I made my best friends by it,we discussed and played together.
But it takes too much time.
The last 10 minutes......
No time to write more.Howerver I love programing for ever.
End at miidle school,restert at university!
Bye!
*/